/*
 * getThresholdedImage.cpp
 *
 *  Created on: Oct 8, 2012
 *      Author: robot
 */
#include <camera/camera.h>

/**
 *	Get a thresholded image.
 *
 *	This removes any parts of the current image that have an
 *	intensity value below a certain threshold. The result is returned
 *	as an IplImage resource.

Mat * Camera::getThresholdedImage(Mat * image)
{
	// Smooth the image.
//	cvSmooth(image, image, CV_GAUSSIAN, 5, 5);

	// Convert the image into an HSV image
	IplImage* imgHSV		= cvCreateImage(cvGetSize(image), 8, 3);
	IplImage* imgV			= cvCreateImage(cvGetSize(image), 8, 1);
	IplImage* imgThreshed	= cvCreateImage(cvGetSize(image), 8, 1);

	cvCvtColor(image, imgHSV, CV_BGR2HSV);
	cvSplit(imgHSV,   imgV, 0, 0, 0);


	double maxV;
	cvMinMaxLoc(imgV, NULL, & maxV, NULL, NULL, NULL);
	maxV *= 0.99;

	// Copy whatever is in range of the maximum value to the imgThreshed resource.
	cvInRangeS(imgHSV, cvScalar(0, 0, maxV-1), cvScalar(255, 255, 255), imgThreshed);

	// Cleanup.
	cvReleaseImage(& imgHSV);
	cvReleaseImage(& imgV);

	return imgThreshed;
}
*/
